package com.itqf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import static org.apache.commons.io.IOUtils.copy;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/12
 * @Time: 上午10:27
 */
@Controller
public class DownloadController {

    //下载
    @RequestMapping("/downloadFile")
    public void   download(HttpServletResponse response){
        String filename = "55a2bfb4-eb75-47f5-933d-f4d8fa625076.gif";
        //设置响应头
        response.setHeader("content-disposition","attachment;filename="+filename);
        File  file = new File("/Users/liliting/Desktop/code/part3/SpringMVCDemo03/src/main/webapp/images",filename);
        try {
            copy(new FileInputStream(file),response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
